home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / httpd / cgi-bin / wais-ncsa-httpd.pl < prev   
Encoding:
Perl Script  |  1995-05-09  |  1.6 KB  |  55 lines

  1. #!/bin/perl
  2. # wais-ncsa-httpd.pl -- WAIS search interface
  3. #
  4. # Tony Sanders <sanders@bsdi.com>, Nov 1993
  5. # Hacked to bloody pieces by marca@ncsa.uiuc.edu.
  6.  
  7. $waisq = "/usr/local/bin/waisq";
  8. $waisd = "/usr/people/marca/localwais/sources";
  9.  
  10. sub do_wais {
  11.     $query = $ARGV[0];
  12.     $pquery = $query;
  13.     $pquery =~ s/%20/ /g;
  14.     
  15.     open(WAISQ, "-|") || exec ($waisq, "-c", $waisd,
  16.                                 "-f", "-", "-S", "www.src", "-g", $pquery);
  17.     print "Content-type: text/html\n\n";
  18.     $title = "WAIS Search Engine";
  19.     print "<HEAD>\n<TITLE>Search of ", $title, "</TITLE>\n</HEAD>\n";
  20.     print "<BODY>\n<H1>", $title, "</H1>\n";
  21.  
  22.     print "Index \`www\' contains the following\n";
  23.     print "items relevant to \`$pquery\':<P>\n";
  24.     print "<DL>\n";
  25.  
  26.     local($hits, $score, $headline, $lines, $bytes, $type, $date);
  27.     while (<WAISQ>) {
  28.         /:score\s+(\d+)/ && ($score = $1);
  29.         /:number-of-lines\s+(\d+)/ && ($lines = $1);
  30.         /:number-of-bytes\s+(\d+)/ && ($bytes = $1);
  31.         /:type "(.*)"/ && ($type = $1);
  32.         /:headline "(.*)"/ && ($headline = $1);         # XXX
  33.         /:date "(\d+)"/ && ($date = $1, $hits++, &docdone);
  34.     }
  35.     close(WAISQ);
  36.     print "</DL>\n";
  37.  
  38.     if ($hits == 0) {
  39.         print "Nothing found.\n";
  40.     }
  41.     print "</BODY>\n";
  42. }
  43.  
  44. sub docdone {
  45.     if ($headline =~ /Search produced no result/) {
  46.         print "Sorry, no search results.<P>\n";
  47.     } else {
  48.         print "<DT><A HREF=\"$headline\">$headline</A>\n";
  49.         print "<DD>Score: $score, Lines: $lines, Bytes: $bytes\n";
  50.     }
  51.     $score = $headline = $lines = $bytes = $type = $date = '';
  52. }
  53.  
  54. eval '&do_wais';
  55.